import { defineConfig } from "vite";
import { fileURLToPath } from "node:url";
import path from "path";
import { viteEjs } from "./vite-plugin-ejs/vite-ejs";
import { ViteImageOptimizer } from 'vite-plugin-image-optimizer';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);




export default defineConfig({
  root: "src",
  plugins: [
    viteEjs(),
    ViteImageOptimizer({})
  ],
  css:{
    devSourcemap: true
  },
  build: {
    assetsInlineLimit: 0,
    minify: false,
    outDir: path.join(__dirname, "dist"),
    rollupOptions: {
      input: ['src/index.html', 'src/about.html'],
      output: { // 配置这个是让不同类型文件放在不同文件夹，不会显得太乱
        chunkFileNames: 'js/[name]-[hash].js',
        entryFileNames: 'js/[name]-[hash].js',
        assetFileNames: 'assets/[ext]/[name]-[hash].[ext]',
        manualChunks (id) { // 静态资源分拆打包
          if (id.includes('node_modules')) {
            return id.toString().split('node_modules/')[1].split('/')[0].toString().replace(/^\./, '')
          }
        }
      }
    }
  }

})